package com.example.javaee.controller;

import com.example.javaee.domain.User;
import com.example.javaee.exception.LoginException;
import com.example.javaee.exception.RegisterException;
import com.example.javaee.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@CrossOrigin
@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    RegisterService registerService;

    @GetMapping("/sendEmail")
    public String sendEmail(@RequestParam String email) throws RegisterException {
        String checkCode = String.valueOf(new Random().nextInt(899999) + 100000);
        return registerService.sendEmail(email);
    }

    @PostMapping("/setUser")
    public void setUserInfo(@RequestBody User user) throws LoginException {
        registerService.setUserInfo(user);
    }
}
